package bill.java.interview.salesforce;

import java.util.LinkedList;
import java.util.List;
import java.util.StringTokenizer;

/***
 * Given a list of commands, build the file system structure
 * mkdir <dir>: make <dir> a subdirectory of the current one, display error
 * "Subdirectory already exists." if <dir> exists. 
 * 
 * cd <dir>: go to subdirectory <dir>, display error "Subdirectory does not exist" if <dir> not found. 
 * 
 * dir: display the current directory and its subdirectories. in the following format: 
 *      Dictory of chain of dir (e.g. root, root\sub1\sub2) subA subB subC
 *      (display up to ten subdirectory each line, each subdirectory is less than 6 characters.) 
 * 
 * up: go to the parent directory
 * 
 * 
 * Sample input:  
 * dir 
 * mkdir sub3 
 * mkdir sub4 
 * midir sub6 
 * dir 
 * cd sub3 
 * cd sub3
 * mkdir sub3 
 * dir 
 * up 
 * up 
 * mkdir sub6 
 * cd sub6 
 * mkdir sub666 
 * up 
 * dir
 * 
 * @author yangliu
 * 
 */

public class SimpleFileSystem {
	private GeneralTreeNode<String> currentNode;
	public GeneralTreeNode<String> getCurrentNode() {
		return currentNode;
	}

	public void setCurrentNode(GeneralTreeNode<String> currentNode) {
		this.currentNode = currentNode;
	}

	public static final String ROOT = "~";
	public static final String ROOT_DISPLAY = "root";

	public static void main(String[] args) {
		String [] inputs = new String[]{
				"dir",
				 "mkdir sub3" ,
				 "mkdir sub4" ,
				 "midir sub6" ,
				 "dir" ,
				 "cd sub3" ,
				 "cd sub3",
				 "mkdir sub3" ,
				 "dir" ,
				 "up" ,
				 "up" ,
				 "mkdir sub6" ,
				 "cd sub6" ,
				 "mkdir sub666" ,
				 "up" ,
				 "dir"
		};
		SimpleFileSystem sfs = new SimpleFileSystem(null);
		
		
	}
	
	private List<String> buildCommand(String line){
		StringTokenizer st = new StringTokenizer(line);
		List<String> result = new LinkedList<String>();
		while(st.hasMoreTokens()){
			result.add(st.nextToken());
		}
		return result;
	}

	public SimpleFileSystem(GeneralTreeNode<String> currentNode) {
		if (currentNode == null) {
			this.currentNode = new GeneralTreeNode<String>(ROOT);
		}else{
			this.currentNode = currentNode;
		}
	}

	public void mkdir(String dirName) {

	}

	public void cd() {

	}

	public void up() {

	}

	public void dir() {

	}

}
